//
//  FiveVC.m
//  yuanjiang
//
//  Created by YuanJiang on 2019/9/19.
//  Copyright © 2019 llbt. All rights reserved.
//

#import "FiveVC.h"
#import "Person.h"
#import <objc/runtime.h>
@interface FiveVC ()

@end

@implementation FiveVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"对私有属性的修改";
    
    
    Person *person  = [[Person alloc] init];
    NSLog(@"person的属性%@",person.description);
    unsigned int count =0;
    Ivar *ivars = class_copyIvarList([Person class], &count);
    for (int i = 0; i<count; i++) {
        Ivar ivar = ivars[i];
        NSLog(@"获取所有的属性%s，%s",ivar_getName(ivar),ivar_getTypeEncoding(ivar));
    }
    //对私有属性的更改
    Ivar m_address = ivars[1];
    
    object_setIvar(person, m_address, @"北京");
    
    NSLog(@"对私有变量进行更改%@",person.description);
}

@end
